package com.idenger.modules.edu.service.user;

import java.util.HashMap;
import java.util.Map;

import com.idenger.modules.edu.dao.user.UserTokenDao;
import com.idenger.modules.edu.entity.user.UserToken;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.idenger.common.service.CrudService;
import com.idenger.modules.edu.entity.user.EduUser;

/**
 * token管理
 * @author kylesean
 * @version 2017-07-12
 * */

@Service
@Transactional(readOnly = false)
public class UserTokenService extends CrudService<UserTokenDao, UserToken>{

	/**
	 * @author kylesean
	 * @param tokenId
	 * 
	 * */
	public UserToken getTokenByTokenId(String tokenId) {
		return dao.getTokenByTokenId(tokenId);
	}
	
	/**
	 * @author kylesean
	 * @param token
	 * 
	 * */
	@Transactional(readOnly = false)
	public void updateUserToken(UserToken token) {
		dao.updateUserToken(token);
	}
	@Transactional(readOnly = false)
	public UserToken queryUserTokenByTel(String mobile) {
		
		return dao.queryUserTokenByTel(mobile);
	}
	@Transactional(readOnly = false)
	public UserToken queryUserTokenByUserId(String user_id) {
		UserToken token =dao.queryUserTokenByUserId(user_id);
		return token;
	}
	@Transactional(readOnly = false)
	public boolean addUserToken(UserToken token) {
		boolean bln = dao.addUserToken(token);
		return bln;
	}
	
	public Map<String, String> getLoginSuccInfo(EduUser user) {
		Map<String, String> result = new HashMap<String, String>();
		UserToken token = queryUserTokenByTel(user.getId());
		if(token == null){
			result.put("1001","暂时没查到数据");
			return result;
		}
		result.put("tokenId", token.getToken());
		result.put("id", String.valueOf(user.getId()));
		return result;
	}
	
	
}
